package com.wjy.common.thread.create;

import com.wjy.common.thread.param.ThreadParams;

import java.util.concurrent.*;

/**
 * @author ybxxszl
 * @desc 线程池创建
 * @date 2019/5/4
 */
public class ThreadPoolCreate {

    private static ThreadFactoryCreate create = new ThreadFactoryCreate();

    private static ThreadPoolExecutor executorSynchronousQueue = new ThreadPoolExecutor(ThreadParams.COREPOOLSIZE,
            ThreadParams.MAXIMUMPOOLSIZE, ThreadParams.KEEPALIVETIME, TimeUnit.SECONDS, new SynchronousQueue<>(),
            create);
    private static ThreadPoolExecutor executorLinkedBlockingDeque = new ThreadPoolExecutor(ThreadParams.COREPOOLSIZE,
            ThreadParams.MAXIMUMPOOLSIZE, ThreadParams.KEEPALIVETIME, TimeUnit.SECONDS,
            new LinkedBlockingDeque<Runnable>(), create);
    private static ThreadPoolExecutor executorArrayBlockingQueue = new ThreadPoolExecutor(ThreadParams.COREPOOLSIZE,
            ThreadParams.MAXIMUMPOOLSIZE, ThreadParams.KEEPALIVETIME, TimeUnit.SECONDS,
            new ArrayBlockingQueue<Runnable>(1), create);

    public static ThreadPoolExecutor getExecutorSynchronousQueue() {
        return executorSynchronousQueue;
    }

    public static ThreadPoolExecutor getExecutorLinkedBlockingDeque() {
        return executorLinkedBlockingDeque;
    }

    public static ThreadPoolExecutor getExecutorArrayBlockingQueue() {
        return executorArrayBlockingQueue;
    }

}
